package com.example.service;


import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;

@Service
public class AsyncServer {

    @Async("async")
    public void asyncTest(Integer counter) throws InterruptedException{
        Thread.sleep(2000);
        System.out.println("线程" + Thread.currentThread().getName() + " 执行异步任务：" + counter);
    }

    @Async("async")
    public void asyncTest2(Integer counter, CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(2000);
        System.out.println("线程" + Thread.currentThread().getName() + " 执行异步任务：" + counter);
        countDownLatch.countDown();
    }
}
